package parts5.lesson71;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 取得文件信息
 */
public class Demo {
    public static void main(String[] args) {

        String str="C:"+ File.separator+"timg.jpg";
        File file=new File(str);
        if(file.isFile()&&file.exists()){
            System.out.println(file.getName());
            long size=file.length();
            double size2=size/(double)1024/(double)1024;
            System.out.println(size2);
            double sizeMB=myRound(size2,2);
            System.out.println(sizeMB+"MB");

            //最后修改日期
            long uTime=file.lastModified();
            System.out.println(uTime);

            String time=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(uTime));
            System.out.println(time);
            System.out.println(file.canExecute());
            System.out.println(file.canRead());
            System.out.println(file.canWrite());
            System.out.println(file.toURI());
        }
    }

    public static double myRound(double size,int i){
        return Math.round(size*Math.pow(10,i))/Math.pow(10,i);
    }
}
